CFLAGS = -g -Werror

CC = gcc 

UTHREADS = user_threads.c user_threads.h

UIO = user_io.c user_io.h

UMUTEX = user_mutex.c user_mutex.h

HEADERS = user_threads.h user_mutex.h user_io.h thread_list.h common.h

all: zombie sanity join_semantics benchmark

user_threads.o: ${UTHREAD} thread_list.h common.h user_mutex.h
	${CC} ${CFLAGS} -c $*.c

user_mutex.o: ${UMUTEX} user_threads.h common.h thread_list.h
	${CC} ${CFLAGS} -c $*.c

user_io.o: ${UIO} user_threads.h common.h thread_list.h
	${CC} ${CFLAGS} -c $*.c

thread_list.o: thread_list.c ${HEADERS}
	${CC} ${CFLAGS} -c $*.c

zombie_tests.o: zombie_tests.c user_threads.h
	${CC} ${CFLAGS} -c $*.c

zombie: zombie_tests.o user_threads.o thread_list.o user_mutex.o
	${CC} ${CFLAGS} zombie_tests.o user_threads.o thread_list.o user_mutex.o -o $@

sanity.o: sanity_threads.c user_thread.h
	${CC} ${CFLAGS} -c $*.c

sanity: sanity_threads.o user_threads.o thread_list.o user_mutex.o
	${CC} ${CFLAGS} sanity_threads.o user_threads.o thread_list.o user_mutex.o -o $@

sieve.o: sieve.c sieve.h
	${CC} ${CFLAGS} -c $*.c

join_semantics.o: join_semantics.c user_threads.h user_mutex.h sieve.h
	${CC} ${CFLAGS} -c $*.c

join_semantics: join_semantics.o user_threads.o sieve.o user_mutex.o thread_list.o
	${CC} ${CFLAGS} join_semantics.o user_threads.o sieve.o user_mutex.o thread_list.o -o $@

uthread_test.o: uthread_test.c user_threads.h user_mutex.h user_io.h thread_list.h
	${CC} ${CFLAGS} -c $*.c

benchmark: uthread_test.o user_threads.o user_io.o user_mutex.o thread_list.o
	${CC} ${CFLAGS} uthread_test.o user_threads.o user_io.o user_mutex.o thread_list.o -o $@

clean:
	rm -f *.o zombie sanity join_semantics benchmark
